from django.template import Library

from projects import utils
from projects.models import Deliverable, Objective, Task

register = Library()

@register.inclusion_tag("task_detail.html")
def show_task_detail(task):
  return {'task_list': [task]}

@register.inclusion_tag("task_table.html")
def list_tasks(tasks):
  return {'task_list': tasks}

@register.inclusion_tag("task_table.html")
def list_complete_subtasks(task):
  return {'task_list': Task.objects.complete().filter(parent = task).order_by('target_date', 'start_date')}

@register.inclusion_tag("task_table.html")
def list_incomplete_subtasks(task):
  return {'task_list': Task.objects.incomplete().filter(parent = task).order_by('target_date', 'start_date')}

@register.inclusion_tag("task_table.html")
def list_complete_tasks(tasks):
  return {'task_list': tasks.exclude(completed_date = None).order_by('target_date', 'start_date')}

@register.inclusion_tag("task_table.html")
def list_incomplete_tasks(tasks):
  return {'task_list': tasks.filter(completed_date = None).order_by('target_date', 'start_date')}

@register.inclusion_tag("task_table.html")
def list_overdue_tasks():
  return {'task_list': Task.objects.overdue().order_by('target_date', 'start_date')}

@register.inclusion_tag("task_table.html")
def list_todays_tasks():
  return {'task_list': Task.objects.dueToday()}

@register.inclusion_tag("rating.html")
def task_status(task):
  assert isinstance(task, Task)
  incomplete_tasks = Task.objects.filter(id = task.id, completed_date = None)
  incomplete_deliverables = Deliverable.objects.none()
  objectives = Objective.objects.none()
  return utils.get_ratings("task", incomplete_tasks, incomplete_deliverables, objectives)

